#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QString>

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_pushButton_clicked()
{
    const int oba_chetnye=1;
    const int chetnoe_0_nechetnoe_1=2;
    const int chetnoe_1_nechetnoe_0=3;
    const int oba_nechetnye=4;

  int curstate=oba_chetnye;
  QString str = ui->textEdit->toPlainText();
  int i=0;
  while(i<str.count())
  {
      if (str.at(i)=='1')
      {
          switch(curstate)
          {
              case(oba_chetnye):
                  curstate=chetnoe_0_nechetnoe_1;
                  break;
              case(chetnoe_0_nechetnoe_1):
                  curstate=oba_chetnye;
                  break;
              case(chetnoe_1_nechetnoe_0):
                  curstate=oba_nechetnye;
                  break;
              case(oba_nechetnye):
                  curstate=chetnoe_1_nechetnoe_0;
                  break;
          }
      }
      if (str.at(i)=='0')
      {
          switch(curstate)
          {
              case(oba_chetnye):
                  curstate=chetnoe_1_nechetnoe_0;
                  break;
              case(chetnoe_0_nechetnoe_1):
                  curstate=oba_nechetnye;
                  break;
              case(chetnoe_1_nechetnoe_0):
                  curstate=oba_chetnye;
                  break;
              case(oba_nechetnye):
                  curstate=chetnoe_0_nechetnoe_1;
                  break;
          }
      }
      i++;
  }
  if (curstate==chetnoe_1_nechetnoe_0)
      ui->textEdit_2->insertPlainText("vce ok");
  else
      ui->textEdit_2->insertPlainText("kosyak");
}
